use axum::Json;
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize)]
pub struct ServerConfig {
    pub listen: String,
    pub bandwidth: BandwidthConfig,
    pub auth: AuthConfig,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct BandwidthConfig {
    pub up: String,
    pub down: String,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct AuthConfig {
    #[serde(rename = "type")]
    pub auth_type: String,
}

pub async fn get_config() -> Json<ServerConfig> {
    // TODO: Load from actual config file
    Json(ServerConfig {
        listen: "0.0.0.0:443".to_string(),
        bandwidth: BandwidthConfig {
            up: "1 gbps".to_string(),
            down: "1 gbps".to_string(),
        },
        auth: AuthConfig {
            auth_type: "password".to_string(),
        },
    })
}

pub async fn update_config(Json(config): Json<ServerConfig>) -> Json<ServerConfig> {
    // TODO: Save to config file
    Json(config)
}

pub async fn validate_config(Json(config): Json<ServerConfig>) -> Json<bool> {
    // TODO: Validate config
    Json(true)
}
